package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.shop.Product;
import com.mvp.shq.washer.utils.DataDictionary;
import com.mvp.shq.washer.utils.ImageUtil;
import com.mvp.shq.washer.utils.OnItemClickListener;
import com.mvp.shq.washer.utils.StringUtils;

import java.math.BigDecimal;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/11.
 */

public class ShopCollectionAdapter extends RecyclerView.Adapter<ShopCollectionAdapter.ViewHolder> {


    private Context context;
    private List<Product> data;
    private ImageUtil imageUtil;
    private OnItemClickListener listener;

    public ShopCollectionAdapter(Context mContext,List<Product> list) {
        context = mContext;
        data = list;
        imageUtil = new ImageUtil(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_shop_collection, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Product product = data.get(position);
//        int type = 0;
//        String money1 = "",money2 = "",integral = "";
//        if (product.getPayMode().equals(DataDictionary.PAY_MODE_CASH_AND_INTEGRAL)){
//            type = 0;
//            money1 = (int)product.getCashPrice()+"";
//            money2 = StringUtils.BigDecimalToStr(BigDecimal.valueOf(product.getCashPrice()));
//            integral = (int)product.getIntegralPrice()+"";
//        }else if (product.getPayMode().equals(DataDictionary.PAY_MODE_CASH)){
//            type = 2;
//            money1 = (int)product.getCashPrice()+"";
//            money2 = StringUtils.BigDecimalToStr(BigDecimal.valueOf(product.getCashPrice()));
//        }else {
//            type = 1;
//            integral = (int)product.getIntegralPrice()+"";
//        }
//        switch (type){
//            case 0:
//                holder.imgProductImg.setImageResource(R.mipmap.product_pictures_1);
//                holder.llMoney.setVisibility(View.VISIBLE);
//                holder.tvAdd.setVisibility(View.VISIBLE);
//                holder.llIntegral.setVisibility(View.VISIBLE);
//                holder.tvIntegralPrompt.setVisibility(View.GONE);
//                holder.tvMoney1.setText(money1);
//                holder.tvMoney2.setText(money2);
//                holder.tvIntegral.setText(integral);
//                break;
//            case 1:
//                holder.llMoney.setVisibility(View.GONE);
//                holder.tvAdd.setVisibility(View.GONE);
//                holder.llIntegral.setVisibility(View.VISIBLE);
//                holder.tvIntegralPrompt.setVisibility(View.VISIBLE);
//                holder.tvIntegral.setText(integral);
//                holder.imgProductImg.setImageResource(R.mipmap.product_pictures_2);
//                break;
//            case 2:
//                holder.llMoney.setVisibility(View.VISIBLE);
//                holder.tvAdd.setVisibility(View.GONE);
//                holder.llIntegral.setVisibility(View.GONE);
//                holder.tvIntegralPrompt.setVisibility(View.GONE);
//                holder.tvMoney1.setText(money1);
//                holder.tvMoney2.setText(money2);
//                holder.imgProductImg.setImageResource(R.mipmap.product_pictures_3);
//                break;
//        }
        holder.llMoney.setVisibility(View.VISIBLE);
        holder.tvAdd.setVisibility(View.GONE);
        holder.llIntegral.setVisibility(View.GONE);
        holder.tvIntegralPrompt.setVisibility(View.GONE);
        holder.tvMoney2.setVisibility(View.GONE);
        holder.tvMoney1.setText(product.getPriceRange());
        holder.tvProductDes.setText(product.getProductName());
        imageUtil.loadUrlImage(product.getImgUrl(),holder.imgProductImg);
        holder.llContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ll_container)
        LinearLayout llContainer;
        @BindView(R.id.img_product_img)
        ImageView imgProductImg;
        @BindView(R.id.tv_product_des)
        TextView tvProductDes;
        @BindView(R.id.tv_money_1)
        TextView tvMoney1;
        @BindView(R.id.tv_money2)
        TextView tvMoney2;
        @BindView(R.id.ll_money)
        LinearLayout llMoney;
        @BindView(R.id.tv_add)
        TextView tvAdd;
        @BindView(R.id.tv_integral)
        TextView tvIntegral;
        @BindView(R.id.ll_integral)
        LinearLayout llIntegral;
        @BindView(R.id.tv_integral_prompt)
        TextView tvIntegralPrompt;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
